package message

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Success bool        `json:"success"`
	Data    interface{} `json:"data,omitempty"`
}

func NewResponse() *Response {
	rsp := new(Response)
	rsp.Code = 0
	rsp.Message = "success"
	rsp.Success = true
	return rsp
}

func NewResponseFor(key string) *Response {
	rsp := new(Response)
	rsp.Code = messages[key].code
	rsp.Message = messages[key].msg
	if rsp.Code == 0 {
		rsp.Success = true
	} else {
		rsp.Success = false
	}
	return rsp
}
